<template>
	<view class="activityDetails">
		<view class="title"> 当前帐号：<text class="yj">{{info.nowVal}}</text> </view>
		
		
		<view class="con">
			<view class="con-tiltle"> 好友： </view>
			<input class="con-ipnut" type="text" v-model="tuanMobile" placeholder="请输入好友的手机号码" value="" />
			<view class="con-but" type="default" @click="turnMy()" v-if="type == 'achievement'"> 到余额 </view>
		</view>
		
		<view class="con">
			<view class="con-tiltle"> 转赠数值： </view>
			<input class="con-ipnut" type="number" v-model="money" placeholder="请输入转赠的数值" value="" />
			<view class="con-but" type="default" @click="turnAll()"> 全部转赠 </view>
		</view>
		
		<view class="but-box" :style="'height:' + bottomHeight + 'rpx;'">
			<view class="but" @click="apply()">确认转赠</view>
		</view>
	</view>
</template>

<script>
	var _self;
	import serve from '../static/request.js';
	import storage from '../static/appkey.js';
	import common from '../static/jump.js';
	export default {
		data() {
			return {
				bottomHeight: 110,/* 底部按钮高度，避免iPhonex导航黑条 */
				info: {
					nowVal: 0,
					mobile: '',
				},
				type: 'achievement',
				tuanMobile: '',
				money: '',
			}
		},
		methods: {
			getMain() {
				serve.request({
					url: '/spread/increase/main',
					data: {
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
						type:_self.type
					}
				}).then(res => {
					_self.info = res.data;
				});
			},
			turnMy() {
				_self.tuanMobile = _self.info.mobile;
			},
			turnAll() {
				_self.money = _self.info.nowVal;
			},
			apply(){
				if(_self.tuanMobile == '') {
					uni.showToast({
						title: "请填写转赠好友手机号码",
						icon: 'none'
					});
					return ;
				}
				if(_self.money == '') {
					uni.showToast({
						title: "请填写转赠数值",
						icon: 'none'
					});
					return ;
				}
				if(_self.money <= 0 || _self.money * 1 > _self.info.nowVal * 1) {
					uni.showToast({
						title: "转赠数值必须大于零并小于当前值",
						icon: 'none'
					});
					return ;
				}
				serve.request({
					url: '/spread/increase/trun',
					data: {
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
						tuanMobile: _self.tuanMobile,
						money: _self.money,
						type: _self.type
					}
				}).then(res => {
					let resuleCode = res.code;
					uni.showToast({
						title: res.message,
						icon: 'none',
						success() {
							if(resuleCode == 200) {
								setTimeout(function() {
									common.jump('return_one');
								}, 2000)
							}
						}
					});
				});
			},
			jump(jump_type, jump_link) {
				common.jump(jump_type, jump_link)
			}
		},
		onLoad(options) {
			_self = this;
			if(uni.getSystemInfoSync().safeAreaInsets.top > 20){
				_self.bottomHeight = 178;
			}
			_self.type = options.type;
			if(_self.type != 'achievement' && _self.type != 'user_integral') {
				uni.showToast({
					title: "错误的访问方式",
					icon : 'none',
					success:function(){ 
						setTimeout(function () { 
							common.jump('return_one')
						}, 2000) 
					} 
				});
				return;
			}
			_self.getMain();
		},
		onShow() {
			
		},
		onPullDownRefresh() {
			
		},
	}
</script>

<style scoped>
	.activityDetails {
		padding: 36rpx;
		padding-bottom: 200rpx;
		font-size: 32rpx;
		color: #1e2022;
	}
	
	.title{    line-height: 100rpx;
    border-bottom: 2rpx solid #ededed;}
	.yj{
		color: #dd6161;
	}
	
	.con{
		display: flex;
		position: relative;
		align-items: center;
		height: 100rpx;
		border-bottom: 2rpx solid #ededed;
	}
	.con-tiltle{}
	.con-ipnut{
		height: 80rpx;
		padding-left: 20rpx;
		color: #dd6161;
		font-size: 30rpx;
	}
	.con-but{
		position: absolute;
		right: 0;
		font-size: 28rpx;
		color: #ffffff;
		padding: 8rpx 16rpx;
		background: #FFBC00;
		border-radius: 8rpx;
	}
	


	.but-box{
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		background: #ffffff;
	}
	.but{
		background: #FFBC00;
		color: #fff;
		border-radius: 0;
		width: 100vw;
		height: 88rpx;
		text-align: center;
		line-height: 88rpx;
		font-size: 36rpx;
	}
	
</style>
